﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AssetsStatistics.aspx.cs"  Inherits="XMK.Tadong.Web.DataAssetsStatistics.AssetsStatistics" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../weblib/jquery.easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../weblib/jquery.easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../weblib/jquery/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../weblib/jquery.easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../webjs/core/index.js" type="text/javascript"></script>
    <link href="../weblib/skins/main.css" rel="stylesheet" type="text/css" />
    
       
        <style type="text/css">
            .query_hint
            {
                border: 5px solid #939393;
                width: 250px;
                height: 50px;
                line-height: 55px;
                padding: 0 20px;
                position: absolute;
                left: 50%;
                margin-left: -140px;
                top: 50%;
                margin-top: -40px;
                font-size: 15px;
                color: #333;
                font-weight: bold;
                text-align: center;
                background-color: #f9f9f9;
                z-index: 100;
            }
            .query_hint img
            {
                position: relative;
                top: 10px;
                left: -8px;
            }
            .cell
            {
                color: #1215ED;
            }
        </style>
        <script type="text/javascript">

        String.prototype.trim=function(){
　　    return this.replace(/(^\s*)|(\s*$)/g, "");
　　 }


    var grid;
    var myDate = new Date()
        $(function () {
//         $('#tt').parent().height($(window).height() - 20);
          grid=$('#tt').treegrid({
            });
            show_query_hint("query_hint");
             $.post( 'AssetsStatistics.aspx?id='+<%=firstId %>,
             function (data) {
                 var arr = [];
                 if (data.rows[0] == null) { return; }
                 for (var a in data.rows[1]) {
                     if (a == "id" || a == "_parentId")
                     { continue; }
                     var obj = {};
                     obj.field = a;
                     obj.title = a;
                     obj.formatter=formatter;
                     arr.push(obj);
                }
              
                grid.treegrid({
                idField: 'id',
                treeField:"_", 
                url:'AssetsStatistics.aspx',
                method: 'get',


                onBeforeLoad: function(row,param){
                    if (!row) {    // load top level rows
                        param.id = 0;    // set id=0, indicate to load new page rows
                    }
                },
                columns:[arr]
            }).treegrid("loadData", data);

           hide_query_hint("query_hint");

          }, 'json');

          $('#tt').treegrid().treegrid('clientPaging');

        });

        (function($){
            function pagerFilter(data){
                if ($.isArray(data)){    // is array  
                    data = {  
                        total: data.length,  
                        rows: data  
                    }  
                }
                var dg = $(this);  
                var state = dg.data('treegrid');
                var opts = dg.treegrid('options');  
                var pager = dg.treegrid('getPager');  
                pager.pagination({  
                    onSelectPage:function(pageNum, pageSize){  
                        opts.pageNumber = pageNum;  
                        opts.pageSize = pageSize;  
                        pager.pagination('refresh',{  
                            pageNumber:pageNum,  
                            pageSize:pageSize  
                        });  
                        dg.treegrid('loadData',state.allRows);  
                        enableClick();
                    }  
                });  
                opts.pageNumber = pager.pagination('options').pageNumber || 1;
                if (!state.allRows){
                    state.allRows = data.rows;
                }
                var topRows = [];
                var childRows = [];
                $.map(state.allRows, function(row){
                    row._parentId ? childRows.push(row) : topRows.push(row);
                });
                data.total = topRows.length;
                var start = (opts.pageNumber-1)*parseInt(opts.pageSize);  
                var end = start + parseInt(opts.pageSize);  
                data.rows = $.extend(true,[],topRows.slice(start, end).concat(childRows));
                return data;
            }
 
            var appendMethod = $.fn.treegrid.methods.append;
            var removeMethod = $.fn.treegrid.methods.remove;
            var loadDataMethod = $.fn.treegrid.methods.loadData;
            $.extend($.fn.treegrid.methods, {
                clientPaging: function(jq){
                    return jq.each(function(){
                        var state = $(this).data('treegrid');
                        var opts = state.options;
                        opts.loadFilter = pagerFilter;
                        var onBeforeLoad = opts.onBeforeLoad;
                        opts.onBeforeLoad = function(row,param){
                            state.allRows = null;
                            return onBeforeLoad.call(this, row, param);
                        }
                        $(this).treegrid('loadData', state.data);
                        if (opts.url){
                            $(this).treegrid('reload');
                        }
                    });
                },
                loadData: function(jq, data){
                    jq.each(function(){
                        $(this).data('treegrid').allRows = null;
                    });
                    return loadDataMethod.call($.fn.treegrid.methods, jq, data);
                },
                append: function(jq, param){
                    return jq.each(function(){
                        var state = $(this).data('treegrid');
                        if (state.options.loadFilter == pagerFilter){
                            $.map(param.data, function(row){
                                row._parentId = row._parentId || param.parent;
                                state.allRows.push(row);
                            });
                            $(this).treegrid('loadData', state.allRows);
                        } else {
                            appendMethod.call($.fn.treegrid.methods, $(this), param);
                        }
                    })
                },
                remove: function(jq, id){
                    return jq.each(function(){
                        if ($(this).treegrid('find', id)){
                            removeMethod.call($.fn.treegrid.methods, $(this), id);
                        }
                        var state = $(this).data('treegrid');
                        if (state.options.loadFilter == pagerFilter){
                            for(var i=0; i<state.allRows.length; i++){
                                if (state.allRows[i][state.options.idField] == id){
                                    state.allRows.splice(i,1);
                                    break;
                                }
                            }
                            $(this).treegrid('loadData', state.allRows);
                        }
                    })
                },
                getAllRows: function(jq){
                    return jq.data('treegrid').allRows;
                }
            });
 
        })(jQuery);

          function formatter(value ,row,index ) {
               if(value.indexOf('/')>0){
                   
                   ss = value.split('/')
                   str ="&nbsp<a class='cell' num='1' row='"+row._+"'  href='#'>"+ss[0].trim()+"</a>&nbsp/&nbsp<a num='2'  row='"+row._+"'  href='#' class='cell'>"+ss[1].trim()+"</a>&nbsp";
                    return str;
               }
               return value;
          }

       function getSubData(obj_id) {

        show_query_hint("query_hint");
         $.post('AssetsStatistics.aspx?id='+obj_id,
             function (data) {
                 var arr = [];
                 if (data.rows[0] == null) { return; }
                 for (var a in data.rows[1]) {
                     if (a == "id"|| a == "_parentId" )
                     { continue; }
                     var obj = {};
                     obj.field = a;
                     obj.title = a;
                     obj.formatter=formatter;
                     arr.push(obj);
                }
               
                grid.treegrid({
                url:'AssetsStatistics.aspx',
                method: 'get',
                columns:[arr]
            }).treegrid("loadData", data);
            hide_query_hint("query_hint");
          }, 'json');
    }

   function show_query_hint(query_hint){
      var query_hint = document.getElementById(query_hint);
      query_hint.style.display="block";
   }

  function  hide_query_hint(query_hint){
      var query_hint = document.getElementById(query_hint);
      query_hint.style.display="none";
      enableClick();
  }

  function enableClick(){
       $(".cell").click(function(){
            var obj= $(this)[0];
            var bus= $( obj.parentNode.parentNode).attr("field");
            var target= $(obj).attr("row");
            var num=  $(obj).attr("num");
            var value = obj.innerHTML;

            if(Number(value)>0)
            {
                if(num==1)
                {
                  window.open("showSearchValue.htm?target="+escape(target)+"&bus="+escape(bus)+"&num="+value);
                }
                else
                {
                 window.open("showSearchFile.htm?target="+escape(target)+"&bus="+escape(bus));
                }

            }
            

          });
          }

        </script>
        <style type="text/css">
            .l-btn-text
            {
                font-size: larger;
            }
        </style>
        <style type="text/css">
            *
            {
                margin: 0;
                padding: 0;
                font-size: 12px;
            }
            ul
            {
                list-style: none;
            }
            ul li a
            {
                text-decoration: none;
                color: #000000;
            }
            ul li a:hover
            {
                text-decoration: underline;
                color: #cc0000;
            }
            #con
            {
                margin: 50px auto;
                width: 960px;
            }
            .tab_Item
            {
                border: 1px solid #d8d9d9;
                width: 99.8%;
            }
            .tab_Tit
            {
                background: url(images/bg.jpg) scroll left top;
                height: 30px;
                background-repeat: repeat;
            }
            
            .tab_Tit a
            {
                float: left;
                display: block;
                padding-top: 8px;
                width: 150px;
                height: 22px;
                border-left: 1px solid #d8d9d9;
                text-align: center;
                cursor: pointer;
            }
            .tab_Tit a:hover
            {
                background: #fff;
                text-decoration: underline;
                color: #cc0000;
            }
            .tab_Tit .selected
            {
                background: #fff;
            }
            .tab_Con
            {
                background: url(images/bg1.jpg) scroll 0 -30px;
                margin: 0px 0 0 0px;
                padding-left: 0px;
                background-repeat: repeat;
            }
            .tab_Con ul
            {
                line-height: 24px;
            }
            .panel-header
            {
                display: none;
            }
        </style>
</head>
<body>
    <form id="form1" runat="server">
    <div data-options="region:'north',border:false" class="topbg" style="height:80px"><div class="logo"></div>
    <div>
      <div id="rightinfo">
         <div class="top_right_exit"><span title="" onclick="logout();"></span></div>
      </div>
     </div>
     </div>
    <div class="tab_Tit">
    
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <a class="" onclick='getSubData(<%#  DataBinder.Eval(Container.DataItem, "obj_id")%>)'>
                    <%# DataBinder.Eval(Container.DataItem, "obj_name")%></a>
            </ItemTemplate>
        </asp:Repeater>
    </div>
    <div class="tab_Con">
        <div>
            <ul id="tableid" class="easyui-treegrid">
            </ul>
        </div>
    </div>
    <div >
        <div id="query_hint" class="query_hint">
            <img src="http://static.oschina.net/uploads/space/2014/0430/115223_oFLD_1163935_thumb.gif" />loading.....
        </div>
        <table id="tt" title="" class="easyui-treegrid" style="height: 550px; overflow: auto"
            data-options=" rownumbers:true, idfield:'id', pagination: true,  pageSize:10, pageList: [2,5,10]">
            <%--  <thead>
                   <tr>
                   <th field="目标" width="450">目标</th>
                   </tr>
                  </thead>--%>
        </table>
    </div>
    </form>
</body>
</html>
